package component;

import java.io.IOException;

import javax.servlet.ServletException;

import atg.droplet.DropletException;
import atg.droplet.GenericFormHandler;
import atg.servlet.DynamoHttpServletRequest;
import atg.servlet.DynamoHttpServletResponse;

/**
 * This is a simple form handler for testing.
 * 
 * @author: jarryzhou
 * @version: 1.0, Oct 26, 2016
 */
public class SimpleFormHandler extends GenericFormHandler {
    private String              mSuccessURL;
    private String              mErrorURL;
    private String              mAnswer;
    private static final String QUESTION = "test";



    public boolean handleTest(final DynamoHttpServletRequest pRequest, final DynamoHttpServletResponse pResponse)
            throws ServletException, IOException {
        if (!QUESTION.equalsIgnoreCase(getAnswer())) {
            addFormException(new DropletException("Your answer is wrong!"));
        }
        return checkFormRedirect(getSuccessURL(), getErrorURL(), pRequest, pResponse);
    }



    public String getSuccessURL() {
        return mSuccessURL;
    }



    public void setSuccessURL(final String pSuccessURL) {
        mSuccessURL = pSuccessURL;
    }



    public String getErrorURL() {
        return mErrorURL;
    }



    public void setErrorURL(final String pErrorURL) {
        mErrorURL = pErrorURL;
    }



    public String getAnswer() {
        return mAnswer;
    }



    public void setAnswer(final String pAnswer) {
        mAnswer = pAnswer;
    }

}
